package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@ToString
public class OrderConfirmVo {

    //收获地址
    @Setter
    @Getter
    List<MemberAddressVo> address;

    //所有选中项的购物项
    @Setter
    @Getter
    List<OrderItemVo> item;
    //发票信息

    //优惠卷信息(会员积分)
    @Setter
    @Getter
    Integer integration;

    //订单总额
    BigDecimal total;

    @Setter
    @Getter
    Map<Long, Boolean> stocks;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (item != null) {
            for (OrderItemVo vo : item) {
                sum = sum.add(vo.getPrice().multiply(new BigDecimal(vo.getCount().toString())));
            }
        }
        return sum;
    }


    //应付价格
    BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    //TODO 防重复提交的令牌
    @Getter
    @Setter
    String OrderToken;

    private Integer count;

    public Integer getCount() {
        Integer sum =0;
        if (item != null) {
            for (OrderItemVo vo : item) {
                sum += vo.getCount();
            }
        }
        return sum;
    }
}
